<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<p id="arrold"></p>
		<p>
			<input type="button" value="升序" onclick="asc()"/>
			<input type="button" value="降序"  onclick="desc()"/>
		</p>
		<p id="arrnew"></p>
		<script>
		var arr=[5,3,8,45,1];
		var old=document.getElementById("arrold");
		old.innerText=arr;
	   function asc(){
	   	  var arrnew=arr.sort(function(a,b){return a-b});
	   	  
		  var news=document.getElementById("arrnew");
		  news.innerText=arrnew;
	   }
	    function desc(){
	   	  var arrnew=arr.sort(function(a,b){return b-a});
		  var news=document.getElementById("arrnew");
		  news.innerText=arrnew;
	   }
		</script>
	</body>
</html>
